﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using ClassLibrary.DAO;
using ClassLibrary.Utilities;
using System.Collections.Generic;
using ClassLibrary.Entity;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label1.Text = "Tp.Buôn Mê Thuột" + ", " + DateTime.Now.ToShortDateString().ToString();
            

            if (Session[Global.SESSION_LOGGED_USER] != "" && Session[Global.SESSION_LOGGED_USER] != null)
            {

                hypDangKy.Visible = hypDangNhap.Visible = false;
                hypThoat.Visible = true;

                TblUserAccount user = (TblUserAccount)Session[Global.SESSION_LOGGED_USER];

                hypName.Text = user.FirstName + " " + user.LastName + " |";
            }
            else
            {
                hypDangKy.Visible = hypDangNhap.Visible = true;
                hypThoat.Visible = false;
                hypName.Text = "";

            }
        }
        UpdateShoppingCartSession();
        LoadCSS();
    }
    protected void hypThoat_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        Session.Abandon();
        Response.Redirect("~/Default.aspx", true);  
    }
    private void LoadCSS()
    {
        string idCSS = Global.GetPageName(Request.ServerVariables["SCRIPT_NAME"].ToString());
        if ((idCSS == "IPod.aspx"))
        {
            ctl00_HyperLink5.Attributes.Add("class", "selected");
        }
        if ((idCSS == "IPad.aspx"))
        {
            ctl00_HyperLink8.Attributes.Add("class", "selected");
        }
        if ((idCSS == "IPhone.aspx"))
        {
            A1.Attributes.Add("class", "selected");
        }
        if ((idCSS == "iMac.aspx"))
        {
            A2.Attributes.Add("class", "selected");
        }
        if ((idCSS == "Default.aspx"))
        {
            ctl00_HyperLink4.Attributes.Add("class", "selected");
        }
      
    }
    public void UpdateShoppingCartSession()
    {
        if (HttpContext.Current.Session[Global.SESSION_CART] != null)
        {
            List<TblOrderDetail> cartItems = (List<TblOrderDetail>)HttpContext.Current.Session[Global.SESSION_CART];

            int iQuantity = 0;
            double dAmount = 0;
            foreach (TblOrderDetail order in cartItems)
            {
                iQuantity += order.Quantity;
                //dAmount +=  order.TotalAmount;
                dAmount += order.Quantity * order.Price;
            }
            lbsoluong.Text = iQuantity.ToString();
            lblAmout.Text = dAmount.ToString("0,00.##");
        }
    }

 
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Result.aspx?text=" + HttpUtility.UrlEncode(txtSearch.Text.Trim()));
    }
}
